<%@page import="cn.sendto.service.ParkInfoService"%>
<%@page import="cn.sendto.model.ParkInfoModel"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"  errorPage="../err.jsp"%>
    <jsp:include page="../lock.jsp"></jsp:include>
<%
	request.setCharacterEncoding("UTF-8");

	String parknum = request.getParameter("parknum");
	String parkposition = request.getParameter("parkposition");
	String parktype = request.getParameter("parktype");
	
	 //验证数据的有效性
    ArrayList<Integer> errlist = new ArrayList<Integer>();
    HashMap<String,String> formlist = new HashMap<String,String>();
    if(parknum == null || parknum.equals("")){
   	 errlist.add(1);
    }else{
    	formlist.put("parknum",parknum);
    }
 
    if(parkposition == null || parkposition.equals("")){
   	 errlist.add(2);
    }else{
    	formlist.put("parkposition", parkposition);
    }

     if(errlist.size()>0){
   	 request.setAttribute("info", errlist);
   	 request.setAttribute("form", formlist);
   	 request.getRequestDispatcher("addpark.jsp").forward(request, response);
   	 return;
    } 
    
     
    //存储数据
    ParkInfoModel pim = new ParkInfoModel();
    pim.setParkNum(parknum);
    pim.setParkPosition(parkposition);
    pim.setParkType(Integer.parseInt(parktype));
    
	
	ParkInfoService pis =new ParkInfoService();
    int rows = pis.add(pim);
    if(rows > 0){
    //返回注册页面
   	 request.setAttribute("addparkinfo","<span style='color:red;'>"+"添加成功"+"</span>"+"，可以继续添加车位或者"+"<a href='parklist.jsp'>点击此处返回业主列表</a>");
   	 request.getRequestDispatcher("addpark.jsp").forward(request, response);
   	 return;
    }else if(rows == -1){
    	 request.setAttribute("addparkinfo", "添加失败,车位已存在");
    	 request.setAttribute("form", formlist);
       	 request.getRequestDispatcher("addpark.jsp").forward(request, response);
       	 return;
    }
    else{
   	 request.setAttribute("addparkinfo", "添加失败。");
   	 request.getRequestDispatcher("addpark.jsp").forward(request, response);
   	 return;
    }
%>